package com.lys.particle;

import com.lys.effect.ModEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.random.Random;

import java.util.List;

public class ParticleHelper {

    public static void MadnessParticle(PlayerEntity player, int particleCount, int radius, Double speed) {
        ServerWorld world = (ServerWorld) player.getEntityWorld();
        Random random = world.getRandom();

        for (int i = 0; i < particleCount; i++) {
            double angle = random.nextDouble() * 2 * Math.PI; // 随机角度
            double x = player.getX() + radius * Math.cos(angle); // 根据角度计算 x 坐标
            double y = player.getY() + random.nextDouble() * 0.5; // 随机高度
            double z = player.getZ() + radius * Math.sin(angle); // 根据角度计算 z 坐标

            // 使用 ParticleTypes 和位置来定义粒子效果
            ParticleEffect particle = ParticleTypes.FLAME;
            world.spawnParticles(particle, x, y, z, 1, 0.0, 0.0, 0.0, speed);

            // 可以根据需要设置粒子的颜色、速度等属性
        }
    }

    public static void MadnessParticle(MinecraftServer minecraftServer) {
        List<ServerPlayerEntity> playerList = minecraftServer.getPlayerManager().getPlayerList();
       if (playerList.size()>0){
           playerList.forEach(player -> {
               if (player.hasStatusEffect(ModEffects.MADNESS)){
                   MadnessParticle(player, 20, 3, 0.0);
               }
           });
       }
    }
}
